package com.ty.blog.controller;

import com.ty.blog.common.utils.PageUtils;
import com.ty.blog.common.utils.R;
import com.ty.blog.dto.req.LabelEntityReq;
import com.ty.blog.entity.LabelEntity;
import com.ty.blog.service.blog.LabelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * 博客标签表
 *
 * @author zhutianyu
 * @email 1659770218@QQ.COM
 * @date 2021-07-28 14:29:38
 */
@Slf4j
@RestController
@RequestMapping("/label")
public class LabelController {
  @Resource
  private LabelService labelService;

  /**
   * 列表
   */
  @PostMapping("/list")
  public R list(@RequestBody LabelEntityReq req) {
    PageUtils page = labelService.queryPage(req);
    return R.ok().put("page", page);
  }

  /**
   * 信息
   */
  @GetMapping("/info/{id}")
  public R info(@PathVariable("id") Long id) {
    LabelEntity xBlogLabel = labelService.getById(id);
    return R.ok().put("info", xBlogLabel);
  }

  /**
   * 保存
   */
  @PostMapping("/save")
  public R save(@RequestBody LabelEntity xBlogLabel) {
    return labelService.save(xBlogLabel) ? R.ok() : R.error();
  }

  /** 修改 */
  @PatchMapping("/update")
  public R update(@RequestBody LabelEntity xBlogLabel) {
    return labelService.updateById(xBlogLabel) ? R.ok() : R.error();
  }

  /** 删除 */
  @DeleteMapping("/delete")
  public R delete(@RequestBody Long[] ids) {
    return labelService.removeByIds(Arrays.asList(ids)) ? R.ok() : R.error();
  }
}
